﻿@model SportMeetingPlanner.ViewModels.MeetingViewModel
@{
    ViewBag.Title = Model.SportName + " events";
}
<br />
<div class="section">
    @using (Html.BeginForm("Index", "Meeting", FormMethod.Post))
    {
        @Html.HiddenFor(m => m.SportId);
    
        <table class="listTable" cellspacing="0">
            <tr>
                <td class="headerColumn" colspan="2">
                    Filter events
                </td>
            </tr>
            <tr>
                <td class="leftColumn">
                    Start Date
                </td>
                <td class="rightColumn">
                    @Html.TextBox("InitDate", Model.StartDate.ToShortDateString(), new { @class = "date", @autocomplete = "off" })
                </td>
            </tr>
            <tr>
                <td class="leftColumn">
                    Final Date
                </td>
                <td class="rightColumn">
                    @Html.TextBox("FinalDate", Model.EndDate.ToShortDateString(), new { @class = "date", @autocomplete = "off" })
                </td>
            </tr>
            <tr class="link">
                <td colspan="2">
                    <input type="submit" value="Filter" />
                </td>
            </tr>
        </table>
    }
</div>
<br />
<div class="section">
    @if (Model != null)
    {
        if (Model.Meetings.Count() > 0)
        {
        <table class="listTable" cellspacing="0">
            <tr>
                <th>
                    Meeting
                </th>
                <th>
                    Date
                </th>
                <th style="padding-right: 20px;">
                    Players
                </th>
            </tr>
            @foreach (var item in Model.Meetings)
            {
                if (item.Players < item.Meeting.Sport.MinPlayers)
                {
                <tr onclick="DoNav('@Url.Content("~/Meeting/Details?id=" + item.Meeting.MeetingId)');" class="linkred">
                    <td>
                        @item.Meeting.Title
                    </td>
                    <td>
                        @item.Meeting.Date.ToShortDateString()
                    </td>
                    <td class="linkColumn">
                        @item.Players
                    </td>
                </tr>
                }
                else
                {
                <tr onclick="DoNav('@Url.Content("~/Meeting/Details?id=" + item.Meeting.MeetingId)');" class="link">
                    <td>
                        @item.Meeting.Title
                    </td>
                    <td>
                        @item.Meeting.Date.ToShortDateString()
                    </td>
                    <td class="linkColumn">
                        @item.Players
                    </td>
                </tr>
                }
            }
            <tr class="link" onclick="DoNav('@Url.Content("~/Meeting/Create?sportId=" + ViewBag.SportId)');">
                <td colspan="3">
                    Add game
                </td>
            </tr>
        </table>
        }
        else
        {
        <table class="listTable" cellspacing="0">
            <tr class="link" onclick="DoNav('@Url.Content("~/Meeting/Create?sportId=" + ViewBag.SportId)');">
                <td colspan="3">
                    Add game
                </td>
            </tr>
        </table>
        }
    }
</div>
